<?php

/**
 * This is the model class for table "{{modalidad}}".
 *
 * The followings are the available columns in table '{{modalidad}}':
 * @property integer $modalidad_id
 * @property string $modalidad_descripcion
 * @property integer $modalidad_deportes
 * @property integer $modalidad_deportes_actividad
 *
 * The followings are the available model relations:
 * @property InscripcionNominal[] $inscripcionNominals
 * @property DeporteActividad $modalidad
 */
class Modalidad extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Modalidad the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{modalidad}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('modalidad_descripcion, modalidad_deportes_actividad', 'required'),
			array('modalidad_deportes, modalidad_deportes_actividad', 'numerical', 'integerOnly'=>true),
			array('modalidad_descripcion', 'length', 'max'=>100),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('modalidad_id, modalidad_descripcion, modalidad_deportes, modalidad_deportes_actividad', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'inscripcionNominals' => array(self::HAS_MANY, 'InscripcionNominal', 'inscripcion_nominal_modalidad'),
			'modalidad' => array(self::BELONGS_TO, 'DeporteActividad', 'modalidad_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'modalidad_id' => 'Modalidad',
			'modalidad_descripcion' => 'Modalidad Descripcion',
			'modalidad_deportes' => 'Modalidad Deportes',
			'modalidad_deportes_actividad' => 'Modalidad Deportes Actividad',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('modalidad_id',$this->modalidad_id);
		$criteria->compare('modalidad_descripcion',$this->modalidad_descripcion,true);
		$criteria->compare('modalidad_deportes',$this->modalidad_deportes);
		$criteria->compare('modalidad_deportes_actividad',$this->modalidad_deportes_actividad);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
		));
	}
}